﻿' ******************************************************************************
' ** 
' **  Yahoo Finance Managed
' **  Written by Marius Häusler 2010
' **  It would be pleasant, if you contact me when you are using this code.
' **  Contact: YahooFinanceManaged@gmail.com
' **  Project Home: http://code.google.com/p/yahoo-finance-managed/
' **  
' ******************************************************************************
' **  
' **  Copyright 2010 Marius Häusler
' **  
' **  Licensed under the Apache License, Version 2.0 (the "License");
' **  you may not use this file except in compliance with the License.
' **  You may obtain a copy of the License at
' **  
' **    http://www.apache.org/licenses/LICENSE-2.0
' **  
' **  Unless required by applicable law or agreed to in writing, software
' **  distributed under the License is distributed on an "AS IS" BASIS,
' **  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
' **  See the License for the specific language governing permissions and
' **  limitations under the License.
' ** 
' ******************************************************************************


Namespace Finance

    ''' <summary>
    ''' Stores informations of base quote values. Implements IID. Serializable. 
    ''' </summary>
    ''' <remarks></remarks>
    <Serializable()> _
    Public Class QuoteBaseData
        Implements IID
        Implements ISettableID

        Private mID As String = String.Empty
        Private mBaseValues(4) As Double
        Private mVolume As Long = 0
        Private mLastTradeDate, mLastTradeTime As Date

        ''' <summary>
        ''' The ID of the QuoteBaseData
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public ReadOnly Property ID() As String Implements IID.ID
            Get
                Return mID
            End Get
        End Property
        ''' <summary>
        ''' Sets a new ID value. Implementation from ISettableID.
        ''' </summary>
        ''' <param name="id">A valid Yahoo! ID</param>
        ''' <remarks></remarks>
        Public Sub SetID(ByVal id As String) Implements ISettableID.SetID
            mID = id
        End Sub
        ''' <summary>
        ''' The price value of the QuoteBaseData
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property LastTradePriceOnly() As Double
            Get
                Return mBaseValues(0)
            End Get
            Set(ByVal value As Double)
                mBaseValues(0) = value
            End Set
        End Property
        ''' <summary>
        ''' The change of the price in relation to close value of the previous day
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Change() As Double
            Get
                Return mBaseValues(1)
            End Get
            Set(ByVal value As Double)
                mBaseValues(1) = value
            End Set
        End Property
        ''' <summary>
        ''' The calculated close price of the last trading day
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>[LastTradePriceOnly] - [Change]</remarks>
        Public ReadOnly Property PreviewClose() As Double
            Get
                Return Me.LastTradePriceOnly - Me.Change
            End Get
        End Property
        ''' <summary>
        ''' The calculated price change in percent
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks>[Change] / [PreviewClose]</remarks>
        Public ReadOnly Property ChangeInPercent() As Double
            Get
                If Me.PreviewClose <> 0 Then : Return Me.Change / Me.PreviewClose
                Else : Return 0
                End If
            End Get
        End Property
        ''' <summary>
        ''' The opening value of the day
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Open() As Double
            Get
                Return mBaseValues(2)
            End Get
            Set(ByVal value As Double)
                mBaseValues(2) = value
            End Set
        End Property
        ''' <summary>
        ''' The highest value of the day
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property DaysHigh() As Double
            Get
                Return mBaseValues(3)
            End Get
            Set(ByVal value As Double)
                mBaseValues(3) = value
            End Set
        End Property
        ''' <summary>
        ''' The lowest value of the day
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property DaysLow() As Double
            Get
                Return mBaseValues(4)
            End Get
            Set(ByVal value As Double)
                mBaseValues(4) = value
            End Set
        End Property
        ''' <summary>
        ''' The trade volume of the day
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Volume() As Long
            Get
                Return mVolume
            End Get
            Set(ByVal value As Long)
                mVolume = value
            End Set
        End Property
        ''' <summary>
        ''' The date value of the data
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property LastTradeDate() As Date
            Get
                Return mLastTradeDate
            End Get
            Set(ByVal value As Date)
                mLastTradeDate = value
            End Set
        End Property
        ''' <summary>
        ''' The time value of the data
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property LastTradeTime() As Date
            Get
                Return mLastTradeTime
            End Get
            Set(ByVal value As Date)
                mLastTradeTime = value
            End Set
        End Property

        ''' <summary>
        ''' Default constructor
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
        End Sub
        ''' <summary>
        ''' Overloaded constructor
        ''' </summary>
        ''' <param name="id">A valid Yahoo! ID</param>
        ''' <remarks>Calls QuoteBaseData.SetID</remarks>
        Public Sub New(ByVal id As String)
            Me.SetID(id)
        End Sub

        ''' <summary>
        ''' Copies the values of a QuoteBaseData to this instance.
        ''' </summary>
        ''' <param name="newValue"></param>
        ''' <remarks></remarks>
        Public Sub CopyData(ByVal newValue As QuoteBaseData)
            If newValue IsNot Nothing Then
                With Me
                    .Change = newValue.Change
                    .DaysHigh = newValue.DaysHigh
                    .DaysLow = newValue.DaysLow
                    .SetID(newValue.ID)
                    .LastTradeDate = newValue.LastTradeDate
                    .LastTradePriceOnly = newValue.LastTradePriceOnly
                    .LastTradeTime = newValue.LastTradeTime
                    .Open = newValue.Open
                    .Volume = newValue.Volume
                End With
            End If
        End Sub

    End Class

End Namespace